package com.iflytek.jcy.supervise.job.service.impl;

import com.iflytek.jcy.supervise.datastore.api.DataSourceHolder;
import com.iflytek.jcy.supervise.datastore.api.JdbcTemplateHolder;
import com.iflytek.jcy.supervise.datastore.dto.TableInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

/**
 * @author <a href=mailto:ktyi@iflytek.com>伊开堂</a>
 * @date 2022/10/20
 */
@Service
public class DataStoreServiceImpl {
    protected final Logger logger = LoggerFactory.getLogger(DataStoreServiceImpl.class);

    @Autowired
    private JdbcTemplateHolder jdbcTemplateHolder;
    @Autowired
    private DataSourceHolder<?> dataSourceHolder;


    public List<TableInfo> fetchAllTables()  {
        try{
            List<TableInfo> tables=dataSourceHolder.readAllTables();
            ResultSet set=dataSourceHolder.getDataSource().getConnection().prepareStatement("select  * from dsr limit 10").executeQuery();

            JdbcTemplate jdbcTemplate = jdbcTemplateHolder.getNamedParameterJdbcTemplate().getJdbcTemplate();
            List <Map <String ,Object >> list=jdbcTemplate.queryForList("select  * from dsr limit 10");
            System.out.println("");
            return tables;
        }catch (Exception e){
            return null;
        }

    }


}
